๋ฌธ์ ์ํฉ
์๋ฌ๋ฌธ
Error occurred prerendering page "/more/board/write". Read more: nextjs.org/docs/messages/prerender-error
ReferenceError: document is not defined
at /vercel/path0/.next/server/chunks/112.js:1:81396
at Array.forEach (<anonymous\>)
at 87731 (/vercel/path0/.next/server/chunks/112.js:1:81384)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143)
at 418 (/vercel/path0/.next/server/app/more/board/write/page.js:1:296)
at Object.t [as require] (/vercel/path0/.next/server/webpack-runtime.js:1:143)
at require (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:140:10304)
at u (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:646)
at U (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:10632)
at W (/vercel/path0/node_modules/.pnpm/next@15.3.1_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:13339)
Export encountered an error on /more/board/write/page: /more/board/write, exiting the build.
โจฏ Next.js build worker exited with code: 1 and signal: null
โELIFECYCLEโ Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1
์ฝ๋
//page.tsx
"use client";
import { useState, useRef } from "react";
import Editor from "./editor";
import Quill, { Delta } from "quill";
import { createBoard } from "@/lib/actions";
export default function Page() {
const quillRef = useRef<Quill | null>(null);
const [title, setTitle] = useState("");
const handleSave = () => {
const delta: Delta | null = quillRef.current?.getContents() || null;
const content = JSON.stringify(delta);
console.log("content : ", content);
if (title && content) {
createBoard(title, content);
}
};
return (
<div className="container mx-auto px-4 py-8 mt-4 bg-gray-200">
<div className="w-full px-10 flex text-3xl items-center relative">
<div>
<span>์ ๋ชฉ</span>
<input
onChange={(e) => { setTitle(e.target.value); }}
className="mx-2 bg-gray-50 rounded-sm py-2
focus:outline-0 text-center border border-gray-300 shadow" >
</input>
</div>
<div
className="flex justify-end gap-2 absolute right-3">
<button
onClick={handleSave}
className="
bg-blue-500 hover:bg-blue-600 text-white
font-medium px-6 py-2 rounded-lg text-lg
shadow-md" >
์์ฑํ๊ธฐ
</button>
</div>
</div>
<div className="my-4 bg-white shadow h-190">
<Editor ref={quillRef} />
</div>
</div>
);
}
//editor.tsx
"use client";
import { useEffect, useRef, RefObject } from "react";
import Quill from "quill";
import "quill/dist/quill.bubble.css";
export default function Editor({ ref }: { ref: RefObject<Quill | null> }) {
const containerRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const container = containerRef.current;
if (container) {
const editorContainer = container.appendChild(
container.ownerDocument.createElement("div")
);
const quill = new Quill(editorContainer, { theme: "bubble" });
ref.current = quill;
return () => {
ref.current = null;
container.innerHTML = "";
};
}
}, [ref]);
return (
<div className="h-full overflow-auto">
<div ref={containerRef} className="ml-20 mt-8 mr-30" />
</div>
);
}
์์ธ
write/page.tsx
๋ฅผ ํ๋ฆฌ๋ ๋๋ง ํ ์ ์์ด์ ๋ฐ์ํ๋ ์๋ฌ.
ํ์ด์ง๋ฅผ ๋ฏธ๋ฆฌ ๋ง๋ค์ด ๋ ๋ ๊ฑฐ๊ธฐ์ ๋ถ๋ฌ์จ quill ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ document
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ DOM API๋ฅผ ํ์๋ก ํ๋ค. (๊ฐ๋ น quill ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์์ document.getElementById
์ ๊ฐ์ ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค)
์ฆ quill์ ์ค์ง์ ์ผ๋ก ์ฌ์ฉํ๋ editor.tsx
์์ ํผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ถ๋ฌ์์ ๋ฌธ์ ๊ฐ ๋๋๊ฒ.
write/page.tsx
์์๋ quill๋ฅผ ๋ถ๋ฌ์ค์ง๋ง ์ฌ๊ธฐ์ ๊ฐ์ฒด๋ฅผ ์์ฑํ์ง๋ ์์๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ๋์ง ์์๋ค.